package com.me.testcustomview;

import java.util.ArrayList;

import android.content.Context;
import android.database.DataSetObserver;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class MyAdapter implements SpinnerAdapter {
	private ArrayList<String> data;
	private LayoutInflater inflater;
	private String title;

	public MyAdapter(Context context, int titleLayoutId, int dropdownLayoutId, String title, ArrayList<String> data) {
		this.data = data;
		this.title = title;
		inflater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		TitleViewHolder holder = new TitleViewHolder();
		if (convertView == null){
		convertView = inflater.inflate(R.layout.ab_title, null);
			holder.tvTitle = (TextView) convertView.findViewById(R.id.tv_ab_title);
			convertView.setTag(holder);
		}
		else holder = (TitleViewHolder)convertView.getTag();
		holder.tvTitle.setText(data.get(position));
		return convertView;
	}

	@Override
	public int getViewTypeCount() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean hasStableIds() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isEmpty() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void registerDataSetObserver(DataSetObserver observer) {
		// TODO Auto-generated method stub

	}

	@Override
	public void unregisterDataSetObserver(DataSetObserver observer) {
		// TODO Auto-generated method stub

	}

	@Override
	public View getDropDownView(int pos, View convertView, ViewGroup parent) {
		DropdownViewHolder dropdownHolder = new DropdownViewHolder();
		if(convertView==null){
			convertView = inflater.inflate(R.layout.ab_dropdown, null);
			dropdownHolder.tvIndex = (TextView) convertView.findViewById(R.id.tv_ab_dropdown);
			dropdownHolder.checkBoxMark = (CheckBox) convertView.findViewById(R.id.checkBox_ab_dropdown);
			convertView.setTag(dropdownHolder);
		}
		else dropdownHolder = (DropdownViewHolder)convertView.getTag();
		
		dropdownHolder.tvIndex.setText(data.get(pos));
	
		return convertView;
	}
	
	class TitleViewHolder{
		TextView tvTitle;
	}
	
	class DropdownViewHolder{
		TextView tvIndex;
		CheckBox checkBoxMark;
	}

}
